package page
{
	import flash.display.DisplayObjectContainer;

	public class PageController
	{
		private var _parent:DisplayObjectContainer;
		private var _currentRunningDemo:Page;

		private static var _instance:PageController;
		
		public function PageController(parent:DisplayObjectContainer, startDemoClass:Class)
		{
			CONFIG::debug
				{
					ASSERT(_instance == null);
				};
			_instance = this;
			
			_parent = parent;
			selectDemo(startDemoClass);
			
		}

		public static function getInstance():PageController
		{
			return _instance;
		}
		
		public function getCurrentPage():Page
		{
			return _currentRunningDemo;
		}
		
		public function selectDemo(demoClass:Class):void
		{
			if(_currentRunningDemo != null)
			{
				_currentRunningDemo.startExiting();
				_currentRunningDemo.exit();
				_currentRunningDemo = null;
			}

			_currentRunningDemo = new demoClass(_parent);
			_currentRunningDemo.enter();

		}
		
	}
}